﻿using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

namespace gKodes.Windows.Forms
{
    /// <summary>
    /// Stores a cell properties the size, padding and segment to which these belongs to
    /// </summary>
    [TypeConverter(typeof(CellPropertiesConverter))]
    public struct CellProperties
    {
        /// <summary>
        /// Initializes a new instance of CellP class with default values
        /// </summary>
        public static readonly CellProperties Default = new CellProperties();//, -1

        #region Private var's

        /// <summary>
        /// Size of the cell in number of charecters
        /// </summary>
        private Size mSize;

        private Padding mPadding;

        private float mDividend;

        //private int mSegment;

        #endregion

        #region Propertie's

        /// <summary>
        /// Gets the size of the cell, measured in number of characters
        /// </summary>
        public Size Size
        {
            get { return this.mSize; }
        }

        public int Width
        {
            get { return this.mSize.Width; }
        }

        public int Height
        {
            get { return this.mSize.Height; }
        }

        /// <summary>
        /// Gets the padding of the cell, measured in pixels
        /// </summary>
        public Padding Padding
        {
            get { return this.mPadding; }
        }

        /// <summary>
        /// 
        /// </summary>
        public float Dividend
        {
            get { return this.mDividend; }
        }

        #endregion

        /// <summary>
        /// Initializes a new instance of CellP from the given parameters, <paramref name="segment"/> 
        /// parameter is optional and its default value is 1 which is the page 
        /// segment number of the Hex View
        /// </summary>
        /// <param name="size">Size of the cell, in number of characters</param>
        /// <param name="padding">Paddint of the cell, in number of pixels</param>
        /// <param name="segment">Segement number to which these setting are meant for</param>
        public CellProperties(Size size, Padding padding)//, int segment = 1
        {
            this.mSize = size;
            this.mDividend = (float)1 / size.Width;
            this.mPadding = padding;
        }

        #region Overriden method's

        #region Operator's

        public static CellProperties operator +(CellProperties cp1, CellProperties cp2)
        {
            return new CellProperties();
        }

        public static CellProperties operator -(CellProperties cp1, CellProperties cp2)
        {
            return new CellProperties();
        }

        public static bool operator ==(CellProperties cp1, CellProperties cp2)
        {
            return (cp1.Size.Equals(cp2) && cp1.Padding.Equals(cp2.Padding));
        }

        public static bool operator !=(CellProperties cp1, CellProperties cp2)
        {
            return !(cp1.Size.Equals(cp2) && cp1.Padding.Equals(cp2.Padding));
        }

        #endregion

        public override bool Equals(object obj)
        {
            if (obj is CellProperties)
                return this.Equals((CellProperties)obj);
            return false;
        }

        public bool Equals(CellProperties obj)
        {
            return (this.mSize.Equals(obj.mSize) && this.mPadding.Equals(obj.mPadding));
        }

        public override int GetHashCode()
        {
            return (this.mSize.Width + this.mSize.Height + this.Padding.Horizontal + this.Padding.Vertical);
        }

        public override string ToString()
        {
            return string.Format("{0}/{1},{2}.{3}.{4}.{5}",
                    this.Size.Width, this.Size.Height,
                    this.Padding.Left, this.Padding.Top,
                    this.Padding.Right, this.Padding.Bottom);
        }

        #endregion
    }
}
